
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>新建mock · sosotest</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="A03_requestmock.html" />
    
    
    <link rel="prev" href="./" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    sosotest平台介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../A0000_quickstart/A00_install.html">
            
                <a href="../A0000_quickstart/A00_install.html">
            
                    
                    安装部署sosotest服务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../A0000_quickstart/">
            
                <a href="../A0000_quickstart/">
            
                    
                    使用配置入门
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../A0000_quickstart/A01_system_config.html">
            
                <a href="../A0000_quickstart/A01_system_config.html">
            
                    
                    管理员配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../A0000_quickstart/A02_user_config.html">
            
                <a href="../A0000_quickstart/A02_user_config.html">
            
                    
                    用户配置
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../A0000_quickstart/A03_interface.html">
            
                <a href="../A0000_quickstart/A03_interface.html">
            
                    
                    用例编写
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../A0000_quickstart/A04_task.html">
            
                <a href="../A0000_quickstart/A04_task.html">
            
                    
                    任务与任务集
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../A0000_quickstart/A05_cicd.html">
            
                <a href="../A0000_quickstart/A05_cicd.html">
            
                    
                    持续集成
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../A0001_admin/">
            
                <a href="../A0001_admin/">
            
                    
                    后台管理部分
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../A0001_admin/A01_login.html">
            
                <a href="../A0001_admin/A01_login.html">
            
                    
                    管理员登录
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../A0001_admin/A02_user_group_manage.html">
            
                <a href="../A0001_admin/A02_user_group_manage.html">
            
                    
                    用户小组管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../A0001_admin/A03_permission.html">
            
                <a href="../A0001_admin/A03_permission.html">
            
                    
                    权限管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../A0001_admin/A04_admin.html">
            
                <a href="../A0001_admin/A04_admin.html">
            
                    
                    管理员管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../A0001_admin/A05_config.html">
            
                <a href="../A0001_admin/A05_config.html">
            
                    
                    平台配置管理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../A0002_user/">
            
                <a href="../A0002_user/">
            
                    
                    用户使用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../A0002_user/A01_config.html">
            
                <a href="../A0002_user/A01_config.html">
            
                    
                    配置管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../A0002_user/A02_http.html">
            
                <a href="../A0002_user/A02_http.html">
            
                    
                    HTTP接口测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../A0002_user/A03_dubbo.html">
            
                <a href="../A0002_user/A03_dubbo.html">
            
                    
                    DUBBO接口测试
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../A0002_user/A04_globalvar.html">
            
                <a href="../A0002_user/A04_globalvar.html">
            
                    
                    全局变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../A0002_user/A05_text.html">
            
                <a href="../A0002_user/A05_text.html">
            
                    
                    组合文本
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="./">
            
                <a href="./">
            
                    
                    MOCK服务
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.6.1" data-path="A02_createmock.html">
            
                <a href="A02_createmock.html">
            
                    
                    新建mock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="A03_requestmock.html">
            
                <a href="A03_requestmock.html">
            
                    
                    请求mock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.3" data-path="A04_recodermock.html">
            
                <a href="A04_recodermock.html">
            
                    
                    mock录制
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../A0004_keyword/">
            
                <a href="../A0004_keyword/">
            
                    
                    关键字模式介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../A0004_keyword/A01_use.html">
            
                <a href="../A0004_keyword/A01_use.html">
            
                    
                    使用关键字
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../A0004_keyword/A02_buildin.html">
            
                <a href="../A0004_keyword/A02_buildin.html">
            
                    
                    内置关键字介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../A0004_keyword/A03_selfdefine.html">
            
                <a href="../A0004_keyword/A03_selfdefine.html">
            
                    
                    自定义关键字
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../A0005_pythonmode/">
            
                <a href="../A0005_pythonmode/">
            
                    
                    python模式介绍
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../A0005_pythonmode/A01_use.html">
            
                <a href="../A0005_pythonmode/A01_use.html">
            
                    
                    使用python模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../A0005_pythonmode/A02_buildin.html">
            
                <a href="../A0005_pythonmode/A02_buildin.html">
            
                    
                    内置python函数介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../A0005_pythonmode/A03_selfdefine.html">
            
                <a href="../A0005_pythonmode/A03_selfdefine.html">
            
                    
                    自定义python
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="../A0005_pythonmode/A04_ddt.html">
            
                <a href="../A0005_pythonmode/A04_ddt.html">
            
                    
                    数据驱动DDT
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../A0010_context/">
            
                <a href="../A0010_context/">
            
                    
                    context上下文对象
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../A0010_context/A01_vars.html">
            
                <a href="../A0010_context/A01_vars.html">
            
                    
                    常用变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../A0010_context/A02_functions.html">
            
                <a href="../A0010_context/A02_functions.html">
            
                    
                    常用函数
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../A0009_data/">
            
                <a href="../A0009_data/">
            
                    
                    数据操作
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../A0009_data/A01_mysqldb.html">
            
                <a href="../A0009_data/A01_mysqldb.html">
            
                    
                    mysql数据库操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../A0009_data/A02_redis.html">
            
                <a href="../A0009_data/A02_redis.html">
            
                    
                    redis缓存操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../A0009_data/A03_mongo.html">
            
                <a href="../A0009_data/A03_mongo.html">
            
                    
                    mongo数据库操作
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../A0006_ci/">
            
                <a href="../A0006_ci/">
            
                    
                    持续集成
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../A0006_ci/A01_invoke.html">
            
                <a href="../A0006_ci/A01_invoke.html">
            
                    
                    invoke接口介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../A0006_ci/A02_cishell.html">
            
                <a href="../A0006_ci/A02_cishell.html">
            
                    
                    CI shell 脚本说明
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../A0007_assert/">
            
                <a href="../A0007_assert/">
            
                    
                    断言处理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../A0007_assert/A01_contains.html">
            
                <a href="../A0007_assert/A01_contains.html">
            
                    
                    包含断言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../A0007_assert/A02_recurjson.html">
            
                <a href="../A0007_assert/A02_recurjson.html">
            
                    
                    递归JSON断言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.3" data-path="../A0007_assert/A03_conditionbool.html">
            
                <a href="../A0007_assert/A03_conditionbool.html">
            
                    
                    条件断言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.4" data-path="../A0007_assert/A04_assertstruct.html">
            
                <a href="../A0007_assert/A04_assertstruct.html">
            
                    
                    结构断言
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../A0008_errors/">
            
                <a href="../A0008_errors/">
            
                    
                    常见错误原因
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../A0008_errors/A03_other.html">
            
                <a href="../A0008_errors/A03_other.html">
            
                    
                    莫名其妙的错误
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >新建mock</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x65B0;&#x5EFA;mock">&#x65B0;&#x5EFA;mock</h1>
<p>&#x65B0;&#x5EFA;mock&#x63A5;&#x53E3;&#xFF0C;&#x83DC;&#x5355;&#x8DEF;&#x5F84;&#x4E3A;<code>&#x6570;&#x636E;&#x670D;&#x52A1;-&gt;HTTP MOCK-&gt;&#x6DFB;&#x52A0;MOCK</code>&#x3002;<br>
<img src="../image/MOCK&#x6DFB;&#x52A0;&#x9875;&#x9762;.png" alt="&#x56FE;&#x7247;">
&#x5B57;&#x6BB5;&#x8BF4;&#x660E;&#xFF1A;<br></p>
<blockquote>
<p>&#x3010;&#x57FA;&#x672C;&#x4FE1;&#x606F;&#x3011;&#x63A5;&#x53E3;&#x540D;&#x79F0;&#xFF1A;&#x8981;mock&#x7684;&#x5373;&#x8BF4;&#x7B80;&#x8981;&#x8BF4;&#x660E;&#x3002;<br>
&#x3010;&#x57FA;&#x672C;&#x4FE1;&#x606F;&#x3011;&#x4E1A;&#x52A1;&#x7EBF;&#xFF1A;&#x4E00;&#x7EA7;&#x5206;&#x7C7B;&#x3002;<br>
&#x3010;&#x57FA;&#x672C;&#x4FE1;&#x606F;&#x3011;&#x6A21;&#x5757;&#xFF1A;&#x4E8C;&#x7EA7;&#x5206;&#x7C7B;&#x3002;<br>
&#x3010;&#x57FA;&#x672C;&#x4FE1;&#x606F;&#x3011;TagKey&#xFF1A;Tag&#x5206;&#x7C7B;&#xFF08;&#x7EAF;&#x82F1;&#x6587;&#xFF09;&#xFF0C;Mock&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x53EF;&#x4EE5;&#x6839;&#x636E;TagKey&#x533A;&#x5206;&#x3002;<br>
&#x3010;MOCK&#x63A5;&#x53E3;&#x4FE1;&#x606F;&#x3011;&#x8BF7;&#x6C42;&#x65B9;&#x6CD5;&#xFF1A;&#x8BF7;&#x6C42;method, POST/GET/DELETE/PUT&#x7B49;&#x3002;<br>
&#x3010;MOCK&#x63A5;&#x53E3;&#x4FE1;&#x606F;&#x3011;&#x670D;&#x52A1;&#xFF1A;&#x670D;&#x52A1;&#x914D;&#x7F6E;&#x7684;http&#x670D;&#x52A1;&#x3002;<br>
&#x3010;MOCK&#x63A5;&#x53E3;&#x4FE1;&#x606F;&#x3011;&#x63A5;&#x53E3;URL&#xFF1A;&#x8981;mock&#x7684;&#x63A5;&#x53E3;url&#x3002;<br>
&#x3010;MOCK&#x63A5;&#x53E3;&#x4FE1;&#x606F;&#x3011;PARAM/HEADER/BODY&#xFF1A;&#x53C2;&#x6570;&#xFF0C;&#x8BF7;&#x6C42;&#x5934;&#x548C;&#x8BF7;&#x6C42;&#x4F53;&#xFF0C;&#x82E5;&#x540C;&#x670D;&#x52A1;&#x540C;tag&#x4E0B;url&#x76F8;&#x540C;&#xFF0C;&#x4F1A;&#x5224;&#x65AD;&#x8FD9;&#x4E9B;&#x4FE1;&#x606F;&#x3002;<br>
&#x3010;MOCK&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#x3011;&#x72B6;&#x6001;&#x7801;&#xFF1A;&#x8FD4;&#x56DE;&#x7684;&#x72B6;&#x6001;&#x7801;&#xFF0C;200/404/302&#x7B49;&#x3002;<br>
&#x3010;MOCK&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#x3011;&#x72B6;&#x6001;&#x539F;&#x56E0;&#xFF1A;&#x8FD4;&#x56DE;&#x7684;&#x72B6;&#x6001;&#x539F;&#x56E0;&#xFF0C;OK/NOT FOUND&#x7B49;&#x3002;<br>
&#x3010;MOCK&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#x3011;&#x54CD;&#x5E94;&#x4F53;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF1A;&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;HTML/XML/JSON&#x7B49;&#x3002;<br>
&#x3010;MOCK&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#x3011;&#x54CD;&#x5E94;&#x4F53;&#x6570;&#x636E;&#x7F16;&#x7801;&#xFF1A;&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x636E;&#x7F16;&#x7801;&#xFF0C;UTF8/GBK&#x7B49;&#x3002;<br>
&#x3010;MOCK&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#x3011;&#x54CD;&#x5E94;&#x4F53;&#x5185;&#x5BB9;&#xFF1A;&#x8FD4;&#x56DE;&#x7684;&#x5185;&#x5BB9;&#x3002;<br>
&#x3010;MOCK&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#x3011;SetCookie&#xFF1A;&#x8BBE;&#x7F6E;&#x8FD4;&#x56DE;&#x7684;cookie&#x3002;<br>
&#x3010;MOCK&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#x3011;SetHeader&#xFF1A;&#x8BBE;&#x7F6E;&#x8FD4;&#x56DE;&#x7684;header&#x3002;<br>
&#x9AD8;&#x7EA7;&#x6A21;&#x5F0F;&#xFF1A;&#x8FDB;&#x5165;&#x9AD8;&#x7EA7;&#x6A21;&#x5F0F;&#xFF0C;&#x53EF;&#x4EE5;&#x7F16;&#x5199;python&#x4EE3;&#x7801;&#x6765;&#x52A8;&#x6001;&#x8FD4;&#x56DE;&#x3002;<br></p>
</blockquote>
<p>1&#x3001;&#x666E;&#x901A;&#x5339;&#x914D;&#x6A21;&#x5F0F;&#xFF1A;<br>
&#x3010;MOCK&#x63A5;&#x53E3;&#x4FE1;&#x606F;&#x3011;&#x4E2D;&#x9009;&#x62E9;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#x3001;&#x670D;&#x52A1;&#x3001;&#x8F93;&#x5165;&#x5B9E;&#x9645;URL&#x3002;<br>
&#x4F8B;&#x5982;&#x8F93;&#x5165;URL&#xFF1A;/getuser&#xFF0C;&#x90A3;&#x4E48;&#x65E0;&#x8BBA;&#x53C2;&#x6570;&#x662F;&#x4EC0;&#x4E48;&#xFF0C;&#x53EA;&#x8981;url&#x662F;/getuser &#x90FD;&#x5C06;&#x8FD4;&#x56DE;&#x6B64;MOCK&#x4FE1;&#x606F;&#x7684;&#x54CD;&#x5E94;&#x5185;&#x5BB9;&#x3002;<br>
<img src="../image/MOCK&#x666E;&#x901A;&#x6A21;&#x5F0F;.png" alt="&#x56FE;&#x7247;"></p>
<p>2&#x3001;&#x6700;&#x5927;&#x5339;&#x914D;&#x6A21;&#x5F0F;&#xFF1A;<br>
&#x3010;MOCK&#x63A5;&#x53E3;&#x4FE1;&#x606F;&#x3011;&#x4E2D;&#x9009;&#x62E9;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#x3001;&#x670D;&#x52A1;&#x3001;&#x8F93;&#x5165;&#x5B9E;&#x9645;URL&#xFF0C;&#x5E76;&#x4E14;&#x53EF;&#x4EE5;&#x8F93;&#x5165;PARAM&#x3001;HEADER&#x548C;BODY&#x3002;<br>
&#x4E3E;&#x4F8B;&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#xFF1A;
<img src="../image/MOCK&#x6700;&#x5927;&#x5339;&#x914D;1.png" alt="&#x56FE;&#x7247;">
<img src="../image/MOCK&#x6700;&#x5927;&#x5339;&#x914D;2.png" alt="&#x56FE;&#x7247;">
&#x4F8B;&#x5982;URL&#x90FD;&#x662F;/getuser&#xFF0C;&#x5047;&#x8BBE;MOCK_HTTP_2&#x7684;PARAM&#x4E3A;id=1&#xFF0C;MOCK_HTTP_3&#x7684;PARAM&#x662F;id=2&#xFF0C;&#x8BF7;&#x6C42;&#x8FDB;&#x6765;&#x65F6;&#xFF0C;&#x5982;&#x679C;id=1&#x5C06;&#x8FD4;&#x56DE;MOCK_HTTP_1&#x4FE1;&#x606F;&#xFF0C;&#x5982;&#x679C;id=2&#x5C06;&#x8FD4;&#x56DE;MOCK_HTTP_2&#x4FE1;&#x606F;&#x3002;<br></p>
<p>3&#x3001;&#x6B63;&#x5219;&#x5339;&#x914D;&#x6A21;&#x5F0F;&#xFF1A;<br>
&#x3010;MOCK&#x63A5;&#x53E3;&#x4FE1;&#x606F;&#x3011;&#x4E2D;&#x9009;&#x62E9;&#x8BF7;&#x6C42;&#x65B9;&#x5F0F;&#x3001;&#x670D;&#x52A1;&#x3001;&#x8F93;&#x5165;URL&#x7684;&#x6B63;&#x5219;&#x8868;&#x8FBE;&#x5F0F;&#x3002;<br>
&#x6BD4;&#x5982;/recommend/100000&#xFF0C;&#x5047;&#x8BBE;100000&#x662F;&#x53D8;&#x91CF;&#xFF0C;&#x53EF;&#x4EE5;&#x5C06;url&#x5199;&#x4E3A; ^/recommend/\d*$ (&#x5FC5;&#x987B;^/&#x5F00;&#x5934;)<br>
<img src="../image/MOCK&#x6B63;&#x5219;restful&#x63A5;&#x53E3;.png" alt="&#x56FE;&#x7247;"></p>
<p>4&#x3001;&#x9AD8;&#x7EA7;&#x6A21;&#x5F0F;&#xFF1A;<br>
&#x52FE;&#x9009;&#x9AD8;&#x7EA7;&#x6A21;&#x5F0F;&#x540E;&#xFF0C;&#x53EF;&#x4EE5;&#x5BF9;&#x8BF7;&#x6C42;&#x7684;&#x53C2;&#x6570;&#x7B49;&#x8FDB;&#x884C;&#x6821;&#x9A8C;&#x548C;&#x5904;&#x7406;&#xFF0C;&#x5E76;&#x6839;&#x636E;&#x7528;&#x6237;&#x8BF7;&#x6C42;&#x4FE1;&#x606F;&#x7684;&#x4E0D;&#x540C;&#xFF0C;&#x8FD4;&#x56DE;&#x4E0D;&#x540C;&#x7684;&#x54CD;&#x5E94;&#x3002;<br>
<br>
&#x76F8;&#x5173;&#x53D8;&#x91CF;&#xFF1A;<br></p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x4F20;&#x5165;&#x7684;&#x53D8;&#x91CF;&#xFF0C;&#x5927;&#x5BB6;&#x53EF;&#x4EE5;&#x8C03;&#x7528;&#xFF0C;&#x505A;&#x903B;&#x8F91;&#x5224;&#x65AD;&#xFF0C;&#x8FD4;&#x56DE;&#x7B49;&#x4F7F;&#x7528;</span>
<span class="hljs-string">&quot;reqMethod&quot;</span>:request.method,  <span class="hljs-comment"># &#x5B9E;&#x9645;&#x8BF7;&#x6C42;&#x7684;method&#xFF0C;GET POST PUT DELTE &#x7B49;&#x7B49;</span>
<span class="hljs-string">&quot;reqUrl&quot;</span>:reqUrl, <span class="hljs-comment"># &#x4E8B;&#x60C5;&#x8BF7;&#x6C42;&#x7684;&#x63A5;&#x53E3;url</span>
<span class="hljs-string">&quot;reqParam&quot;</span>:reqParam, <span class="hljs-comment"># &#x8BF7;&#x6C42;&#x884C;&#x4E2D;&#x7684;&#x53C2;&#x6570;&#x5B57;&#x7B26;&#x4E32; k=1&amp;m=2</span>
<span class="hljs-string">&quot;reqBody&quot;</span>: reqBody,  <span class="hljs-comment"># &#x8BF7;&#x6C42;&#x4F53;&#x5185;&#x5BB9;</span>
<span class="hljs-string">&quot;reqHeader&quot;</span>: processedReqHeader,  <span class="hljs-comment"># &#x8BF7;&#x6C42;header&#xFF0C;key&#x90FD;&#x662F;&#x5927;&#x5199;</span>

<span class="hljs-string">&quot;GET&quot;</span>: request.GET, <span class="hljs-comment"># GET&#x7684;&#x53C2;&#x6570;dict</span>
<span class="hljs-string">&quot;POST&quot;</span>: request.POST, <span class="hljs-comment"># POST&#x7684;&#x53C2;&#x6570;dict</span>

<span class="hljs-comment"># &#x4EE5;&#x4E0B;&#x4E3A;&#x8981;&#x8D4B;&#x503C;&#x7684;&#x5B57;&#x6BB5;</span>
<span class="hljs-comment"># &#x662F;&#x5426;&#x4F7F;&#x7528;&#x4EE3;&#x7801;&#x4E2D;&#x7684; resp&#x76F8;&#x5173;&#x7684;&#x6570;&#x636E;&#xFF0C;&#x4E0D;&#x4F7F;&#x7528;&#x5C31;&#x4F7F;&#x7528;&#x9ED8;&#x8BA4;&#x7684;&#xFF0C;&#x53EA;&#x6709;&#x4E3A;True&#x7684;&#x65F6;&#x5019;&#xFF0C;&#x8D4B;&#x503C;&#x7684;resp&#x76F8;&#x5173;&#x7684;&#x6570;&#x636E;&#x624D;&#x4F1A;&#x751F;&#x6548;&#xFF0C;&#x5982;&#x679C;isResp&#x4E3A;False&#xFF0C;</span>
<span class="hljs-comment"># &#x6216;&#x8005;&#x4E3A;True&#x4F46;&#x662F;&#x6CA1;&#x6709;&#x5BF9;resp*&#x76F8;&#x5173;&#x7684;&#x53C2;&#x6570;&#x8FDB;&#x884C;&#x91CD;&#x65B0;&#x8D4B;&#x503C;&#xFF0C;&#x90A3;&#x4E48;resp*&#x76F8;&#x5173;&#x7684;&#x503C;&#x53D6;MOCK&#x54CD;&#x5E94;&#x4FE1;&#x606F;&#x4E2D;&#x7684;&#x503C;</span>
<span class="hljs-string">&quot;isResp&quot;</span>: <span class="hljs-keyword">False</span>,
<span class="hljs-string">&quot;respStatusCode&quot;</span>:respStatusCode, <span class="hljs-comment">#&#x8FD4;&#x56DE;&#x7684;&#x72B6;&#x6001;&#x7801;&#xFF0C;&#x9ED8;&#x8BA4; 200</span>
<span class="hljs-string">&quot;respStatusReason&quot;</span>:respStatusReason, <span class="hljs-comment">#&#x8FD4;&#x56DE;&#x7684;reason&#xFF0C;&#x9ED8;&#x8BA4; OK</span>
<span class="hljs-string">&quot;respContentType&quot;</span>:respContentType, <span class="hljs-comment">#&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x636E;&#x7C7B;&#x578B;&#xFF0C;&#x9ED8;&#x8BA4;None</span>
<span class="hljs-string">&quot;respCharset&quot;</span>:respCharset, <span class="hljs-comment">#&#x8FD4;&#x56DE;&#x7684;&#x5B57;&#x7B26;&#x96C6;&#xFF0C;&#x9ED8;&#x8BA4;None</span>
<span class="hljs-string">&quot;respContent&quot;</span>:respContent, <span class="hljs-comment">#&#x8FD4;&#x56DE;&#x7684;&#x54CD;&#x5E94;&#x4F53;</span>
<span class="hljs-string">&quot;respCookie&quot;</span>:respCookie, <span class="hljs-comment"># json string &#x6216;&#x8005; &quot;&quot;&#x7A7A;&#x5B57;&#x7B26;&#x4E32;</span>
<span class="hljs-string">&quot;respHeader&quot;</span>:respHeader, <span class="hljs-comment"># json string &#x6216;&#x8005; &quot;&quot;&#x7A7A;&#x5B57;&#x7B26;&#x4E32;</span>
</code></pre>
<p><br>
&#x9ED8;&#x8BA4;&#x5F15;&#x5165;&#x7684;&#x5305;<br></p>
<pre><code class="lang-python"><span class="hljs-comment"># &#x5B57;&#x7B26;&#x4E32;&#x5904;&#x7406;&#x76F8;&#x5173;&#x7684;&#x5E93;</span>
<span class="hljs-keyword">import</span> json,re,jsonpath,hashlib,ast
<span class="hljs-keyword">from</span> urllib <span class="hljs-keyword">import</span> parse
<span class="hljs-keyword">from</span> functools <span class="hljs-keyword">import</span> reduce
<span class="hljs-keyword">from</span> bs4 <span class="hljs-keyword">import</span> BeautifulSoup
<span class="hljs-comment"># &#x65F6;&#x95F4;&#x5904;&#x7406;&#x76F8;&#x5173;&#x7684;&#x5E93;</span>
<span class="hljs-keyword">import</span> datetime,time,calendar
<span class="hljs-comment"># &#x6570;&#x5B66;&#x5904;&#x7406;</span>
<span class="hljs-keyword">import</span> math,cmath,decimal
<span class="hljs-comment">#web&#x8BF7;&#x6C42;&#x76F8;&#x5173;</span>
<span class="hljs-keyword">import</span> requests
<span class="hljs-comment"># &#x5F02;&#x5E38;&#x5904;&#x7406;</span>
<span class="hljs-keyword">import</span> traceback
<span class="hljs-comment"># &#x6570;&#x636E;&#x5E93;&#x76F8;&#x5173;</span>
<span class="hljs-keyword">import</span> pymysql,redis
<span class="hljs-keyword">from</span> kafka <span class="hljs-keyword">import</span> KafkaProducer
<span class="hljs-keyword">from</span> kafka <span class="hljs-keyword">import</span> KafkaConsumer
<span class="hljs-keyword">from</span> kafka.errors <span class="hljs-keyword">import</span> KafkaError
</code></pre>
<p>&#x793A;&#x4F8B;&#xFF1A;<br>
&#x5047;&#x8BBE;MOCK&#x63A5;&#x53E3;/getuser&#xFF0C;&#x9AD8;&#x7EA7;&#x6A21;&#x5F0F;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;<br>
<img src="../image/MOCK&#x9AD8;&#x7EA7;&#x6A21;&#x5F0F;&#x4EE3;&#x7801;.png" alt="&#x56FE;&#x7247;">
&#x4EE3;&#x7801;&#x4EE5;&#x53CA;&#x6CE8;&#x91CA;&#x5982;&#x4E0B;&#xFF1A;<br></p>
<pre><code class="lang-python">isResp = <span class="hljs-keyword">True</span> <span class="hljs-comment"># &#x4F7F;&#x7528;&#x9AD8;&#x7EA7;&#x6A21;&#x5F0F;&#x4E2D;&#x7684;resp*&#x76F8;&#x5173;&#x7684;&#x5185;&#x5BB9;&#x4F5C;&#x4E3A;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;&#x8FD4;&#x56DE;&#x3002;</span>
<span class="hljs-comment">#&#x9ED8;&#x8BA4;&#x8FD4;&#x56DE;&#x7684;dict&#xFF0C;&#x6700;&#x7EC8;&#x8981;&#x8F6C;&#x6362;&#x4E3A;json&#x5B57;&#x7B26;&#x4E32;</span>
default_dict = {<span class="hljs-string">&quot;code&quot;</span>:<span class="hljs-number">10000</span>, <span class="hljs-string">&quot;msg&quot;</span>:<span class="hljs-string">&quot;ok&quot;</span>, <span class="hljs-string">&quot;body&quot;</span>:[{<span class="hljs-string">&quot;id&quot;</span>:<span class="hljs-number">1</span>,<span class="hljs-string">&quot;username&quot;</span>:<span class="hljs-string">&quot;nobody&quot;</span>}]} 
id = GET.get(<span class="hljs-string">&quot;id&quot;</span>,<span class="hljs-string">&quot;&quot;</span>) <span class="hljs-comment"># &#x83B7;&#x53D6;&#x8BF7;&#x6C42;&#x53C2;&#x6570;&#x4E2D;&#x7684;id</span>
<span class="hljs-keyword">if</span> id == <span class="hljs-string">&quot;100001&quot;</span>:
    <span class="hljs-comment">#&#x5982;&#x679C;id&#x662F;100001</span>
    default_dict[<span class="hljs-string">&quot;body&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;id&quot;</span>] = <span class="hljs-number">100001</span> <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x8FD4;&#x56DE;&#x7684;&#x7528;&#x6237;id&#x662F;100001</span>
    default_dict[<span class="hljs-string">&quot;body&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;username&quot;</span>] = <span class="hljs-string">&quot;&#x5F20;&#x4E09;&quot;</span> <span class="hljs-comment"># &#x8BBE;&#x7F6E;&#x8FD4;&#x56DE;&#x7684;&#x7528;&#x6237;username&#x662F;&#x5F20;&#x4E09;</span>
    respContent = json.dumps(default_dict) <span class="hljs-comment"># &#x5C06;&#x8FD4;&#x56DE;&#x4FE1;&#x606F;&#x8F6C;&#x4E3A;json</span>
<span class="hljs-keyword">elif</span> id == <span class="hljs-string">&quot;100002&quot;</span>:
    <span class="hljs-comment"># &#x5982;&#x679C;id&#x662F;100002&#xFF0C;&#x8DDF;100001&#x5904;&#x7406;&#x903B;&#x8F91;&#x4E00;&#x81F4;</span>
    default_dict[<span class="hljs-string">&quot;body&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;id&quot;</span>] = <span class="hljs-number">100002</span>
    default_dict[<span class="hljs-string">&quot;body&quot;</span>][<span class="hljs-number">0</span>][<span class="hljs-string">&quot;username&quot;</span>] = <span class="hljs-string">&quot;&#x674E;&#x56DB;&quot;</span>
    respContent = json.dumps(default_dict)
<span class="hljs-keyword">else</span>:
    <span class="hljs-comment"># &#x5982;&#x679C;&#x662F;&#x5176;&#x4ED6;&#x7684;id&#xFF0C;&#x8FD4;&#x56DE;404 NOT FOUND.</span>
    default_dict = {<span class="hljs-string">&quot;code&quot;</span>:<span class="hljs-number">10001</span>, <span class="hljs-string">&quot;msg&quot;</span>:<span class="hljs-string">&quot;No user found!&quot;</span>, <span class="hljs-string">&quot;body&quot;</span>:[]} 
    respStatusCode = <span class="hljs-number">404</span>
    respStatusReason = <span class="hljs-string">&quot;NOT FOUND&quot;</span>
    respContent = json.dumps(default_dict)
</code></pre>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="./" class="navigation navigation-prev " aria-label="Previous page: MOCK服务">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="A03_requestmock.html" class="navigation navigation-next " aria-label="Next page: 请求mock">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"新建mock","level":"1.6.1","depth":2,"next":{"title":"请求mock","level":"1.6.2","depth":2,"path":"A0003_mock/A03_requestmock.md","ref":"A0003_mock/A03_requestmock.md","articles":[]},"previous":{"title":"MOCK服务","level":"1.6","depth":1,"path":"A0003_mock/README.md","ref":"A0003_mock/README.md","articles":[{"title":"新建mock","level":"1.6.1","depth":2,"path":"A0003_mock/A02_createmock.md","ref":"A0003_mock/A02_createmock.md","articles":[]},{"title":"请求mock","level":"1.6.2","depth":2,"path":"A0003_mock/A03_requestmock.md","ref":"A0003_mock/A03_requestmock.md","articles":[]},{"title":"mock录制","level":"1.6.3","depth":2,"path":"A0003_mock/A04_recodermock.md","ref":"A0003_mock/A04_recodermock.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["expandable-chapters","theme-comscore","splitter"],"styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"splitter":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"sosotest","gitbook":"*","theme-default":{"showLevel":true}},"file":{"path":"A0003_mock/A02_createmock.md","mtime":"2019-06-19T09:46:46.734Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-06-19T14:58:27.203Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

